package com.goldenautumn.prefabricate

import android.app.Application
import android.content.Context
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ProcessUtils
import com.blankj.utilcode.util.Utils
import com.goldenautumn.prefabricate.activity.splash.StatisticActivityLifecycleCallback
import qncx.external.common.BuildConfig
import qncx.external.common.Global
import qncx.external.common.base.remote.Remote
import qncx.external.common.compat.currentProcessName
import qncx.external.common.network.RetrofitManager
import qncx.external.common.utils.TUIRouter

class GoldenAutumnApplication : Application() {

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)

        Global.init(this)

        RetrofitManager.init()

        TUIRouter.init(this)

    }

    override fun onCreate() {
        super.onCreate()

        Utils.init(this)

        LogUtils.getConfig().setConsoleSwitch(BuildConfig.DEBUG)
        LogUtils.getConfig().globalTag = "GoldenAutumn"


        if (currentProcessName == packageName) Remote.launch()

        if (ProcessUtils.isMainProcess()) {
            registerActivityLifecycleCallbacks(StatisticActivityLifecycleCallback())
        }
    }

    fun finalize() {
        Global.destroy()
    }

}
